package com.ruoyi.pcj.controller;

import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.ruoyi.common.annotation.Log;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pcj.domain.PcjChatGroupUser;
import com.ruoyi.pcj.service.IPcjChatGroupUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 聊天室-人员Controller
 *
 * @author ms
 * @date 2024-02-29
 */
@RestController
@RequestMapping("/pcj/chatGroupUser")
public class PcjChatGroupUserController extends BaseController {
    @Autowired
    private IPcjChatGroupUserService pcjChatGroupUserService;

    /**
     * 分页查询聊天室-人员列表
     *
     * @param params 最基本参数{"pageNum":1,"pageSize":10}，其他参数自行定义
     */
    @PreAuthorize("@ss.hasPermi('pcj:chatGroupUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam Map<String, Object> params) {
        IPage<PcjChatGroupUser> page = pcjChatGroupUserService.selectPcjChatGroupUserList(params);
        return getDataTableMp(page);
    }
    /**
     * 分页查询聊天室-人员列表，
     *
     * @param params 最基本参数{"pageNum":1,"pageSize":10,groupId:"聊天室id"}
     */
    @PreAuthorize("@ss.hasPermi('pcj:chatGroupUser:list')")
    @GetMapping("/getData")
    public TableDataInfo getData(@RequestParam Map<String, Object> params) {
        IPage<PcjChatGroupUser> page = pcjChatGroupUserService.getData(params);
        return getDataTableMp(page);
    }


    /**
     * 导出聊天室-人员列表
     */
    @PreAuthorize("@ss.hasPermi('pcj:chatGroupUser:export')")
    @Log(title = "聊天室-人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody Map<String, Object> params) {
        IPage<PcjChatGroupUser> page = pcjChatGroupUserService.selectPcjChatGroupUserList(params);
        ExcelUtil<PcjChatGroupUser> util = new ExcelUtil<PcjChatGroupUser>(PcjChatGroupUser.class);
        util.exportExcel(response, page.getRecords(), "聊天室-人员数据");
    }

    /**
     * 获取聊天室-人员详细信息
     */
    @PreAuthorize("@ss.hasPermi('pcj:chatGroupUser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(pcjChatGroupUserService.selectPcjChatGroupUserById(id));
    }

    /**
     * 新增聊天室-人员
     */
    @PreAuthorize("@ss.hasPermi('pcj:chatGroupUser:add')")
    @Log(title = "聊天室-人员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PcjChatGroupUser pcjChatGroupUser) {
        return toAjax(pcjChatGroupUserService.insertPcjChatGroupUser(pcjChatGroupUser));
    }

    /**
     * 修改聊天室-人员
     */
    @PreAuthorize("@ss.hasPermi('pcj:chatGroupUser:edit')")
    @Log(title = "聊天室-人员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PcjChatGroupUser pcjChatGroupUser) {
        return toAjax(pcjChatGroupUserService.updatePcjChatGroupUser(pcjChatGroupUser));
    }

    /**
     * 删除聊天室-人员
     */
    @PreAuthorize("@ss.hasPermi('pcj:chatGroupUser:remove')")
    @Log(title = "聊天室-人员", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(pcjChatGroupUserService.deletePcjChatGroupUserByIds(ids));
    }
}
